<?php


class Cms_Model_Xtension extends WSB_Db_Row
{

	public function init()
	{
		$this->_formConfigPath = WSB_MODULES_PATH . 'cms/forms/xtension.config';
	}

	/**
	 * @var string
	 */
	public function getTitle()
	{
	   return $this->name;
	}

	/**
	 * Konfigurations-Objekt fuer aktuelle Modulinstanz zurueckgeben.
	 *
	 * @return Zend_Config
	 */
	public function getConfig()
	{
		$config = trim($this->cfg);
		if(empty($config)) {
			return null;
		} else {
			$configArray = WSB_Div::iniToArray($config);
			return new Zend_Config($configArray);
		}
	}

	/**
	 * @todo: Caching!!!
	 * @return SimpleXMLElement|boolean
	 */
	public function getDescriptor()
	{
		$descriptorPath = sprintf('%s%s/etc/descriptor.xml', WSB_XTENSION_PATH, strtolower($this->class));
		if(is_readable($descriptorPath)) {
			$xml = simplexml_load_file($descriptorPath, 'Cms_Model_XtensionDescriptor');
			return $xml;
		}
		return null;
	}

	/**
	 * Gib den Modulnamen (fuer den Gebrauch im Pfadsegment)
	 *
	 * @return string
	 */
	public function getModuleName()
	{
		return 'xt'.strtolower($this->class);
	}

	/**
	 * @return string
	 */
	public function getControllerDirectory()
	{
		$directory = sprintf('%s%s/module/controllers', WSB_XTENSION_PATH, strtolower($this->class));
		if(is_dir($directory)) {
			return $directory;
		}
	}

}